<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title></title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
    <style>
        .index-outside > section .section-main {
            min-width: 0px !important;
            padding: 15px;
        }

        .index-outside > section {
            padding-bottom: 0px !important;
        }

        .cover-content .cover-img {
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<!--头部-->
<div class="index-outside">
    <!--内容-->
    <section class="no-fix">
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/help/help/saveOrUpdateClassify.do">
                    <input type="hidden" name="id" value="${help.id}"/>
                        <div class="layui-form-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">分类名称<span class="f-verify-red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" lay-verify="title" autocomplete="off"
                                           class="layui-input" value="${help.title}" maxlength="7"
                                           style="width: 200px; float: left; margin-right: 10px;"
                                    >
                                    <div class="layui-form-mid layui-word-aux">最多7字符</div>
                                </div>
                            </div>
                        </div>

                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序<span class="f-verify-red">*</span></label>
                            <div class="layui-input-block">
                                <input type="number" name="sort" lay-verify="sort" autocomplete="off"
                                       class="layui-input" value="${help.sort}" maxlength="5"
                                       onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode) ) )'
                                       style="width: 200px; float: left; margin-right: 10px;"
                                >
                                <div class="layui-form-mid layui-word-aux">请输入数字</div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script>
    $(function () {
        layui.use(['form', 'laydate'], function () {

        });
    });


    function ajaxSubmit(data, url, cb) {
        $.ajax({
            type: 'POST',
            async: false, // 使用同步的方法
            data: data,
            dataType: 'json',
            success: function (result) {
                typeof cb === 'function' && cb(result);
            },
            url: url
        });
    }

    function verify() {
        var flag = true;
        var title = $("[name=title]").val();
        var sort = $("[name=sort]").val();
        if (!util.isValid(title)) {
            util.layerMsgError("分类名称不能为空")
            return false;
        }else if (!util.isValid(sort)){
            util.layerMsgError("排序不能为空")
            return false;
        } else {
            function cb(res) {
                flag = res.success;
                if (!res.success) {
                    util.layerMsgError(res.description)
                    return false;
                }
            }

            ajaxSubmit({
                name: name,
                id: '${mallCategory.id}',
                parentId : '${mallCategory.parentId}'
            }, '${ctx}/mall/category/verifyName.do', cb);
        }

        return flag;
    }

    function doSubmit() {
        var flag = false;
        if (verify()) {
            ajaxSubmit($('#myForm').serialize(), $("#myForm").attr('action'), function (res) {
                flag = res.success;
                if (res.success) {
                    util.layerMsgSuccess("提交成功")
                } else {
                    util.layerMsgError(res.description)
                }
            });
        }
        return flag;
    }

    function openDialog() {
        $(parent.$.find(".layui-layer-iframe")[0]).css("width", "900px");
        $(parent.$.find(".layui-layer-iframe")[0]).css("height", "730px");
        $(parent.$.find(".layui-layer-iframe")[0]).find("iframe").css("height", "630px");
    }

    function closeDialog() {
        $(parent.$.find(".layui-layer-iframe")[0]).css("width", "800px");
        $(parent.$.find(".layui-layer-iframe")[0]).css("height", "570px");
        $(parent.$.find(".layui-layer-iframe")[0]).find("iframe").css("height", "470px");
    }
</script>
</body>
</html>